import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class test {
    public static void main(String[] args) {
        String str = "123";
        try {
            //加密
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            String s = new BigInteger(1, md5.digest(str.getBytes())).toString(32);
            String s1 = new String(s.getBytes());
            System.out.println(str); //123
            System.out.println(s); //105ism5b2p0tdpcio72kmi6irg
            System.out.println(s1);//105ism5b2p0tdpcio72kmi6irg
            String ebncode = EncoderByMd5(str);
            System.out.println(ebncode);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        //确定计算方法
        MessageDigest md5=MessageDigest.getInstance("MD5");
        BASE64Encoder base64en = new BASE64Encoder();
        //加密后的字符串
        String newstr=base64en.encode(md5.digest(str.getBytes("utf-8")));
        return newstr;
    }
}
